#include "AspectEngine.h"

namespace agtk {

Logger::Logger(char* filename)
{
	// Open the logfile for writing. Will automatically create if it doesn't exist.
	m_fLogfile = fopen( filename, "w" );
}

Logger::~Logger(void)
{
	// Close the logfile.
	fclose (m_fLogfile);
}

void Logger::Log(int type, char* msg, char* extra)
{
	char* typeChar = "";
	
	switch (type) {
		case LOGGER_ERROR:
			typeChar = "Error";
			break;
		case LOGGER_WARNING:
			typeChar = "Warning";
			break;
		case LOGGER_INFO:
			typeChar = "Info";
			break;
		default:
			typeChar = "Info";
			break;
	}
		
	// If logfile is open, write message with carriage return.
	if( m_fLogfile != NULL )
		fprintf( m_fLogfile, "%s - %s  %s\n", typeChar, msg, extra );
	
	// Output message to console if we want it.
	#ifndef LOG_QUIETLY
	std::cout << "Log msg: " << typeChar << " - " << msg << " " << extra << std::endl;
	#endif
}

}